package cn.acheng1314.springboot2.mapper

import cn.acheng1314.springboot2.entity.AdminUser
import com.baomidou.mybatisplus.core.conditions.Wrapper
import com.baomidou.mybatisplus.core.mapper.BaseMapper
import org.apache.ibatis.annotations.*
import org.apache.ibatis.session.RowBounds
import org.springframework.stereotype.Repository


/**
 * Created by pc on 2017/8/11.
 */
@Repository
interface AdminUserMapper : BaseMapper<AdminUser> {

    @Select("SELECT * FROM `sys_admin_user`")
    fun findAll(): List<AdminUser>

    @Select("SELECT * FROM `sys_admin_user` where `login_name` = #{key}")
    fun findOneByKey(@Param("key") key: String): AdminUser

    @Update("UPDATE `sys_admin_user` SET `used` = 0 where `login_name` = #{key}")
    fun delUser(@Param("key") key: String)

    @Insert("INSERT `sys_admin_user` " +
            "(`name`,`login_name`, `password`, `duty`, `create_date`, `used`)" +
            "    VALUES (#{name}, #{loginName}, #{password}, #{duty}, #{createDate}, #{used});")
    @SelectKey(statement = arrayOf("SELECT LAST_INSERT_ID()"), keyProperty = "id", before = false, resultType = Long::class)
    fun addUser(adminUser: AdminUser)

    fun selectPage(rowBounds: RowBounds, wrapper: Wrapper<AdminUser>): List<AdminUser>

    fun selectNotUsed(): List<AdminUser>
}
